﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kokomo
{
	public static class StringExtensions
	{
		public static TEnum ParseEnumValue<TEnum>(this string text, bool ignoreCase)
		{
			return (TEnum)Enum.Parse(typeof(TEnum), text, ignoreCase);
		}
		public static void SplitKeyValue(this string text, char separator, bool trimWhiteSpace, out string key, out string value)
		{
			if (text == null)
			{
				key = value = null;
			}

			int iSeparator = text.IndexOf(separator);
			if (iSeparator >= 0)
			{
				key = text.Substring(0, iSeparator);
				value = text.Substring(iSeparator + 1);
			}
			else
			{
				key = text;
				value = null;
			}

			if (trimWhiteSpace)
			{
				key = key.Trim();
				if (value != null)
				{
					value = value.Trim();
				}
			}
		}
	}
}
